
import processing.core.PApplet;

public class Timer2 
{
    public Jeu program;
    int timestart;
    
    int start;
    int s;
    int m;
    int h;
    
    int oldTime = 0;
    
    public Timer2(Jeu app) 
    {
        timestart = app.millis();
        start = app.millis();
        program = app;
    }
    
    public int getTime()
    {
        int passedTime = (program.millis() - timestart)/1000;
        return passedTime;
    }
    
    public void displayTime()
    {
        String time = getTimeGame();
        program.text("TIME", 1193, 625);
        program.text(time,  1167, 640);
    }
    
    public boolean getTimeForUpRessource()
    {
        int passedTime = getTime();
        
        if( oldTime != passedTime )
        {
            setOldTime(passedTime);
            return true;
        }
        else
            return false;
    }
    
    public String getTimeGame()
    {
        int s = (program.millis() - start)/1000;
        
        return getDurationString(s);
    }
    
    private String getDurationString(int seconds) 
    {

        int hours = seconds / 3600;
        int minutes = (seconds % 3600) / 60;
        seconds = seconds % 60;

        return twoDigitString(hours) + " : " + twoDigitString(minutes) + " : " + twoDigitString(seconds);
    }
    
    private String twoDigitString(int number) 
    {
        if (number == 0) 
        {
            return "00";
        }

        if (number / 10 == 0) 
        {
            return "0" + number;
        }
        return String.valueOf(number);
    }

    public int getOldTime()
    {
        return oldTime;
    }

    public void setOldTime(int oldTime)
    {
        this.oldTime = oldTime;
    }
    
    
}
